package com.web.estate.common;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.CharEncoding;
import org.apache.log4j.Logger;

public final class PasswordEncrypt {

	private static Logger logger = Logger.getLogger(PasswordEncrypt.class);

	public static String createMD5(String passwordSource) {
		if (passwordSource == null) {
			return null;
		}
		try {
			return Base64.encodeBase64String(DigestUtils.md5(passwordSource.getBytes(CharEncoding.UTF_8)));
		} catch (UnsupportedEncodingException ex) {
			logger.error(ex.getStackTrace());
			return passwordSource;
		}
	}
}
